package com.sjy.project.ent.user.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sjy.framework.aspectj.lang.annotation.Log;
import com.sjy.framework.aspectj.lang.enums.BusinessType;
import com.sjy.project.ent.user.domain.EntUser;
import com.sjy.project.ent.user.service.IEntUserService;
import com.sjy.framework.web.controller.BaseController;
import com.sjy.framework.web.domain.AjaxResult;
import com.sjy.common.utils.poi.ExcelUtil;
import com.sjy.framework.web.page.TableDataInfo;

/**
 * 企业用户信息Controller
 * 
 * @author ljb
 * @date 2022-06-04
 */
@Controller
@RequestMapping("/ent/user")
public class EntUserController extends BaseController
{
    private String prefix = "ent/user";

    @Autowired
    private IEntUserService entUserService;

    @RequiresPermissions("ent:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询企业用户信息列表
     */
    @RequiresPermissions("ent:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EntUser entUser)
    {
        startPage();
        List<EntUser> list = entUserService.selectEntUserList(entUser);
        return getDataTable(list);
    }

    /**
     * 导出企业用户信息列表
     */
    @RequiresPermissions("ent:user:export")
    @Log(title = "企业用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EntUser entUser)
    {
        List<EntUser> list = entUserService.selectEntUserList(entUser);
        ExcelUtil<EntUser> util = new ExcelUtil<EntUser>(EntUser.class);
        return util.exportExcel(list, "企业用户信息数据");
    }

    /**
     * 新增企业用户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业用户信息
     */
    @RequiresPermissions("ent:user:add")
    @Log(title = "企业用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EntUser entUser)
    {
        return toAjax(entUserService.insertEntUser(entUser));
    }

    /**
     * 修改企业用户信息
     */
    @RequiresPermissions("ent:user:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EntUser entUser = entUserService.selectEntUserById(id);
        mmap.put("entUser", entUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业用户信息
     */
    @RequiresPermissions("ent:user:edit")
    @Log(title = "企业用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EntUser entUser)
    {
        return toAjax(entUserService.updateEntUser(entUser));
    }

    /**
     * 删除企业用户信息
     */
    @RequiresPermissions("ent:user:remove")
    @Log(title = "企业用户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(entUserService.deleteEntUserByIds(ids));
    }
}
